package shellstation;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;

public class User1 extends JFrame implements ActionListener  {
    User1 us;
    private int u;
    private boolean watcher= false;
    private int yesNo;
    private int uss;
    private JFrame frame;

    private JPanel panel;
    private JPanel panel2;

    private JMenuBar menuBar;

    private JMenu file;

    private JMenuItem mainMenu;
    private JMenuItem logOut;

    private JLabel shellLabel;
    private JLabel shellText;
    private JLabel shellText2;
    private JLabel shellText3;

    private JButton addUserButton;

    private JButton viewUserButton;

    private JButton backButton;

    private Icon editIcon;
    private Icon deleteIcon;
    private Icon backIcon;
    private Icon shellIcon;

    private Color yellow = new Color(255, 218, 63);
    private Color gray = new Color(222,222,222);
    private Color red = new Color(226, 0, 0);


    public void User1() {

     editIcon = new ImageIcon(getClass().getResource("image/editUser.gif"));
     deleteIcon = new ImageIcon(getClass().getResource("image/deleteUser.gif"));
     backIcon = new ImageIcon(getClass().getResource("image/back.png"));
     shellIcon = new ImageIcon(getClass().getResource("image/shell.gif"));
      menuBar= new JMenuBar();
        file= new JMenu("File");
        mainMenu= new JMenuItem("Main Menu");
        logOut= new JMenuItem("Log Out");
         menuBar.add(file);
        file.add(mainMenu);
        file.add(logOut);


        shellLabel = new JLabel();
        shellLabel.setIcon(shellIcon);
        shellLabel.setBounds(150, 75, 150, 150);

        shellText = new JLabel("Sta. Elena Shell Station");
        shellText.setBounds(55, 150, 400, 200 );
        shellText.setFont(new Font("Hobo Std", Font.BOLD, 32));

        shellText2 = new JLabel("Inventory and Sales");
        shellText2.setBounds(88, 175, 350, 200);
        shellText2.setFont(new Font("Hobo Std", Font.BOLD, 32));

        shellText3 = new JLabel("System");
        shellText3.setBounds(170, 200, 300, 200);
        shellText3.setFont(new Font("Hobo Std", Font.BOLD, 32));

        frame = new JFrame("Shell Station - Inventroy Sales System");
        frame.setSize(750, 450);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setJMenuBar(menuBar);

        mainMenu.addActionListener(this);
        logOut.addActionListener(this);

        addUserButton = new JButton("Add User");
        addUserButton.setBackground(gray);
        addUserButton.setBounds(18, 25,250, 75);
        addUserButton.setFont(new Font("Arial", Font.BOLD, 20));
        addUserButton.addActionListener(this);

        viewUserButton = new JButton("View User");
        viewUserButton.setBackground(gray);
        viewUserButton.setBounds(18, 145, 250, 75);
        viewUserButton.setFont(new Font("Arial", Font.BOLD, 20));
        viewUserButton.addActionListener(this);

        backButton= new JButton("Go Back", backIcon);
        backButton.setBackground(gray);
        backButton.setBounds(18, 265, 250, 75);
        backButton.setFont(new Font("Arial", Font.BOLD, 20));
        backButton.addActionListener(this);


        panel = new JPanel(null);
        panel.setBackground(red);

        panel2= new JPanel(null);
        panel2.setBounds(300, 0, 750, 424);
        panel2.setBackground(yellow);



        addpanelComponents();
        addpanel2Components();

        panel.add(panel2);
        frame.add(panel);
    }

    public void actionPerformed(ActionEvent e){




         if(e.getSource() == addUserButton)
        {
             if(watcher == true){
               yesNo =JOptionPane.showConfirmDialog(null, "Do you want to go to Add User?", null, JOptionPane.YES_NO_OPTION);
           }
             if(yesNo == JOptionPane.YES_OPTION || watcher == false){

           watcher = true;
          panel2.removeAll();
          panel2.repaint();
             AddUser a = new AddUser();
             a.AddUser();
            panel2.add(a.getUserType());
            panel2.add(a.getUserName());
            panel2.add(a.getPassword());
            panel2.add(a.getConfirmPassword());
            panel2.add(a.getSecurityQ());
            panel2.add(a.getSecurityA());
            panel2.add(a.getuserType());
            panel2.add(a.getUname());
            panel2.add(a.getPword());
            panel2.add(a.getCPword());
            panel2.add(a.getSQ());
            panel2.add(a.getSA());
            panel2.add(a.getsubmit());

            panel2.repaint();
            panel2.revalidate();
            }
             
         
        }

        else if(e.getSource() == viewUserButton ){
            if(watcher == true ){
                yesNo =JOptionPane.showConfirmDialog(null, "Do you want to go to View User?", null, JOptionPane.YES_NO_OPTION);
            }
            if(yesNo == JOptionPane.YES_OPTION){
           watcher = true;
          panel2.removeAll();
          panel2.repaint();
          Userview u = new Userview();
          u.Userview();
          u.getJPanel(panel2);

          panel2.add(u.getscrollPanel());
          panel2.add(u.getsubmit());
          panel2.add(u.getedit());
          panel2.add(u.getUserType());
          panel2.add(u.getUsertype());
          panel2.add(u.getUsername());
          panel2.add(u.getUname());
          panel2.add(u.getsearch());


          panel2.repaint();
          panel2.revalidate();
         }
            
         
         
        }

          else if(e.getSource() == backButton ){

         MainMenu m = new MainMenu();
         frame.dispose();
         m.MainMenu();
         m.getuser(this.u);


        }

            else if(e.getSource() == mainMenu){

            frame.dispose();
            MainMenu m= new MainMenu();
            m.MainMenu();
            m.getuser(this.u);
        }

         else if(e.getSource() == logOut){
         int i=JOptionPane.showConfirmDialog(null, "Are you sure you want to Logout?", "Confirm Logout", JOptionPane.YES_NO_OPTION);
         if(i==0){
         Main m = new Main();
         JOptionPane.showMessageDialog( null, "Good bye!" );
         frame.dispose();
         m.main();
        }
         }
         

       


    }
    public void getuser(int u){
        this.u = 0;
        this.u = u;
    }

    public void getchoice(int us){
        this.uss=us;
    }

    public void addpanelComponents(){

        panel.add(addUserButton);
        panel.add(viewUserButton);
        panel.add(backButton);

    }

    public void addpanel2Components(){

        panel2.add(shellLabel);
        panel2.add(shellText);
        panel2.add(shellText2);
        panel2.add(shellText3);
    }

    public void getuser1(User1 us){
        this.us = us;

    }

    public static void main(String[]  args){
        User1 u = new User1();
        u.User1();
    }
}

